package org.algorithm.Recursion;

//使用递归的二分查找
public class BinarySearchUseRecursion
{

    public int search(int [] array,int target)
    {
        return fun(array, target, 0, array.length - 1);
    }


    private int fun(int []array,int target,int left ,int right) {

        if (left>right)
        {
            return -1;
        }
        int mid = (left+right)>>>1;

        if (target<array[mid])
        {
           return fun(array,target,left,mid-1);
        }else if (array[mid]<target)
        {
           return fun(array,target,mid+1,right);
        }else {
            return mid ;
        }
    }

    public static void main(String[] args) {
        BinarySearchUseRecursion binarySearchUseRecursion = new BinarySearchUseRecursion();

        int [] array ={1,2,3,6,5,4};

        System.out.println(binarySearchUseRecursion.search(array,0));
    }
}
